package com.tsugun.mediaplayer.view.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tsugun.mediaplayer.R;

import java.util.List;

import static com.tsugun.mediaplayer.presenter.utils.SettingPreferenceHelper.*;

/**
 * 列表适配器
 * Created by shize on 2017/3/30.
 */

public class FolderItemAdapter extends RecyclerView.Adapter<FolderItemAdapter.RecyclerViewHolder> {

    private LayoutInflater mInflater;
    private List<String> mData;
    private OnFolderItemClickListener mOnFolderItemClickListener;

    public interface OnFolderItemClickListener {
        void onItemClick(int position);
    }

    public FolderItemAdapter(Context mContext, List<String> mData) {
        this.mData = mData;
        mInflater = LayoutInflater.from(mContext);
    }

    public void setOnMusicItemClickListener(OnFolderItemClickListener onFolderItemClickListener) {
        mOnFolderItemClickListener = onFolderItemClickListener;
    }

    @Override
    public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new RecyclerViewHolder(mInflater.inflate(R.layout.item_folder, parent, false));
    }

    @Override
    public void onBindViewHolder(final RecyclerViewHolder holder, int position) {
        holder.mTvTitle.setText(mData.get(position));
        if (mOnFolderItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnFolderItemClickListener.onItemClick(holder.getAdapterPosition());
                }
            });
        }

        setSettingTheme(holder);
    }

    // 设置主题
    private void setSettingTheme(RecyclerViewHolder holder) {
        holder.mTvTitle.setTextColor(INSTANCE.getTEXT_COLOR());
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class RecyclerViewHolder extends RecyclerView.ViewHolder {

        TextView mTvTitle;

        RecyclerViewHolder(View itemView) {
            super(itemView);
            mTvTitle = (TextView) itemView.findViewById(R.id.id_folder_title);
        }
    }
}
